/*
 * Copyright 2016-2018 TVI Go Easy.
 * Created on 2018/1/30 22:22
 */
package com.tvi.cloud.license.message;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;

import java.text.MessageFormat;

/**
 * 消息消费监听
 *
 * @author mechanic
 */
@Slf4j
//告诉服务使用 Sink 接口中定义的通道来监听传入的消息。
@EnableBinding(Sink.class)
public class MessageListener {

    @StreamListener(Sink.INPUT) //每当收到来自输入通道的消息时， Spring Cloud Stream 将执行此方法。
    public void printSink(OrganizationChangeModel orgChange) {
        log.debug(MessageFormat.format("Received an {0} event for organization id {1}",
                orgChange.getAction(),
                orgChange.getOrganizationId()));
//        System.out.println(MessageFormat.format("Received an {0} event for organization id {1}",
//                orgChange.getAction(),
//                orgChange.getOrganizationId()));
    }
}
